package com.example.lock;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author xiejp on 2022/5/17
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws Exception {
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\tupdate mysql ok");
        });
        //completableFuture.get();
        CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "\tinsert mysql ok");
            int age  = 10/0;
            return 1024;
        }).whenComplete((t, u) -> {
            System.out.println(t);
            System.out.println(u);
        }).exceptionally(f -> {
            System.out.println(f.getMessage());
            return 11;
        });
    }
}
